// pages/one_info/one_info.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    group_number: '???',
    ifmask: false,
    actions: [
      {
        name: '删除',
        color: '#fff',
        fontsize: '20',
        width: 60,
        background: '#ed3f14'
      },
    ],
    toggle2: false,
    group: [{
      name: '加载中...',
      ID: '0'
    }, {
      name: '加载中...',
      ID: '1'
    }],
    if_Show_members: false,
    show_text: 'ʕ￫ᴥ￩ʔ点此管理成员~(˘▾˘~)'
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    this.setData({
      group_number: options.group_number
    })
    wx.request({
      url: 'https://localhost:8080/getecd',
      data: {
        groupID: that.data.group_number
      },
      success(res) {
        that.setData({ imgurl: "data:image/PNG;base64," + res.data })
      }
    })
    wx.request({
      url: 'https://localhost:8080/getgroupinfo_n_ID_num_rw',
      data: {
        groupID: that.data.group_number
      },
      success(res) {
        if (res.data.errCode == 2020) {
          that.setData({ info: res.data })
        }
        else if (res.data.errCode == 2019) {
          wx.showToast({
            title: res.data.errmsg,
            icon: 'none'
          })
        }
      }
    })
  },

  Bcopy:function(){
    var that =this
    wx.setClipboardData({
      data: that.data.group_number,
      success: function (res) {
        wx.getClipboardData({
          success: function (res) {
            wx.showToast({
              title: '复制成功'
            })
          }
        })
      }
    })
  },

  BLsave: function () {
    var imgSrc = this.data.imgurl.slice(22);//base64编码
    var save = wx.getFileSystemManager();
    var number = Math.random();
    save.writeFile({
      filePath: wx.env.USER_DATA_PATH + '/pic' + number + '.png',
      data: imgSrc,
      encoding: 'base64',
      success: res => {
        wx.saveImageToPhotosAlbum({
          filePath: wx.env.USER_DATA_PATH + '/pic' + number + '.png',
          success: function (res) {
            wx.showToast({
              title: '保存成功',
            })
          },
          fail: function (err) {
            console.log(err)
          }
        })
        console.log(res)
      }, fail: err => {
        console.log(err)
      }
    })
  },

  del: function (e) {
    var that = this
    console.log(e.currentTarget.dataset.id)
    wx.showModal({
      title: '提示',
      content: '确认要从该小组中删除该成员?',
      success: function (res) {
        if (res.confirm) {
          wx.request({
            url: 'https://localhost:8080/delfromgroup',
            data:{
              openID:e.currentTarget.dataset.id,
              groupnum:that.data.group_number
            },
            success(res){
              if(res.data.errCode==2020){
                wx.showToast({
                  title:'删除成功'
                })
                wx.request({
                  url: 'https://localhost:8080/admingroup',
                  data: {
                    groupnum: that.data.group_number
                  },
                  success(res) {
                    if (res.data == '0') {
                      wx.showToast({
                        title: '异常!',
                        icon: 'none'
                      })
                    }
                    else {
                      that.setData({
                        group: res.data
                      })
                    }
                  }
                })
              }
              else if(res.data.errCode==2019){
                wx.showToast({
                  title:'删除失败，请查看帮助',
                  icon:'none'
                })
              }
            }
          })
        }
      }
    })
  },

  mask: function () {
    var that = this
    this.setData({
      ifmask: !(that.data.ifmask)
    })
  },

  Show_members: function () {
    var that = this
    if (this.data.if_Show_members == false) {
      this.setData({
        if_Show_members: true,
        show_text: '⊙﹏⊙|||点此收起成员(╬◣д◢)'
      })
    }
    else if (this.data.if_Show_members == true) {
      this.setData({
        if_Show_members: false,
        show_text: 'ʕ￫ᴥ￩ʔ点此管理成员~(˘▾˘~)'
      })
    }
    if (this.data.group[0].ID == 0) {
      var that = this
      //request
      wx.request({
        url: 'https://localhost:8080/admingroup',
        data: {
          groupnum: that.data.group_number
        },
        success(res) {
          if (res.data == '0') {
            wx.showToast({
              title: '异常!',
              icon: 'none'
            })
          }
          else {
            that.setData({
              group: res.data
            })
          }

        }
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})